class Solution {
public:
    int compareVersion(string version1, string version2) {
        int ptr1 = 0, ptr2 = 0;
        while (ptr1 < version1.size() || ptr2 < version2.size()) {
            int n1 = 0, n2 = 0;
            while (ptr1 < version1.size() && version1[ptr1] != '.') {
                n1 *= 10;
                n1 += version1[ptr1] - '0';
                ptr1++;
            }
            while (ptr2 < version2.size() && version2[ptr2] != '.') {
                n2 *= 10;
                n2 += version2[ptr2] - '0';
                ptr2++;
            }
            if (n1 < n2) return -1;
            else if (n1 > n2) return 1;
            else ptr1++, ptr2++;
        }
        return 0;
    }
};